package jianzhioffer.list;

import algorithm.model.ListNode;

import java.util.ArrayList;

/**
 * 从尾到头打印列表
 * Created by antony on 2019-11-01 19:45
 */
public class PrintListFromTailToHead {

    public ArrayList<Integer> printListFromTailToHead(ListNode listNode) {
        ArrayList<Integer> list = new ArrayList<>();
        return toList(list, listNode);
    }

    private static ArrayList toList(ArrayList list, ListNode listNode){
        if(listNode == null){
            return list;
        }
        list = toList(list, listNode.next);
        list.add(listNode.val);
        return list;
    }
}
